﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data;
using System.Configuration;
using System.Windows.Forms;

namespace Du_Lich
{
   
    class TuyenDung
    {
        private SqlConnection conn = null;
        private SqlCommand cmd = null;
        private SqlDataAdapter da = null;

        string strConn = ConfigurationManager.ConnectionStrings["DuLich"].ConnectionString.ToString();

        public void MoKetNoi()
        {
            conn = new SqlConnection(strConn);
            if (conn.State == ConnectionState.Closed)
                conn.Open();
        }

        public void DongKetNoi()
        {
            if (conn.State == ConnectionState.Open)
                conn.Close();
        }

        public void ThemNVTuyenDung(string manv, string hoten, string phai,string ngaysinh,string diachi,string quanhuyen, string trinhdo,string lopdaotao)
        {
            try
            {
                conn = new SqlConnection(strConn);
                string sqlInsert = "Insert TUYENDUNGNHANVIEN values(@manv,@hoten,@phai,@ngaysinh,@diachi,@quanhuyen,@trinhdo,@lopdaotao)";
                cmd = new SqlCommand(sqlInsert, conn);

                cmd.Parameters.AddWithValue("@manv", manv);
                cmd.Parameters.AddWithValue("@hoten", hoten);
                cmd.Parameters.AddWithValue("@phai", phai);
                cmd.Parameters.AddWithValue("@ngaysinh", ngaysinh);
                cmd.Parameters.AddWithValue("@diachi", diachi);
                cmd.Parameters.AddWithValue("@quanhuyen", quanhuyen);
                cmd.Parameters.AddWithValue("@trinhdo", trinhdo);
                cmd.Parameters.AddWithValue("@lopdaotao", lopdaotao);
               
                if (conn.State == ConnectionState.Closed)
                    conn.Open();
                cmd.ExecuteNonQuery();
                conn.Close();

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        public void XoaNVTuyenDung(string manv)
        {
            string sqlDelete = "Delete TUYENDUNGNHANVIEN where MaNV=@manv";
            cmd = new SqlCommand(sqlDelete, conn);
            cmd.Parameters.AddWithValue("@manv", manv);
            if (conn.State == ConnectionState.Closed)
                conn.Open();
            cmd.ExecuteNonQuery();
            conn.Close();
        }

        public DataTable ThongTinNhanVien()
        {
            string sqlThongTin = "Select * from TUYENDUNGNHANVIEN";
            cmd = new SqlCommand(sqlThongTin, conn);
            SqlDataAdapter da = new SqlDataAdapter(sqlThongTin, conn);
            DataTable dt = new DataTable();
            da.Fill(dt);
            return dt;
        }

        public void Rong(string manv, string hoten, string phai, string diachi, string quanhuyen, string trinhdo, string lopdaotao)
        {
            manv = " ";
            hoten = " ";
            phai = " ";
            diachi = " ";
            quanhuyen = " ";
            trinhdo = " ";
            lopdaotao = " ";
        }

        internal void ThemNVTuyenDung()
        {
            throw new NotImplementedException();
        }
    }
}
